<?php

Class Help{
    
    var $location = array();
    var $countLocation = 6;
    
    /**
     * 
    */
    function __construct(){
        $this->location = $this->getLocations();
        _echo("count(location) ".count( $this->location) );
        if( count( $this->location ) == 0 ){            
            $this->location["showRosha"] = 0;
			$this->location["showRoshaSteal"] = 0;
 			$this->location["showShop"] = 0;
			$this->location["showIzba"] = 0;			
			$this->location["showPereputie"] = 0;
			$this->location["showMagicBook"] = 0; 
            
            /*$i = 1;
            while($i <= $this->countLocation){
                _echo(0);
                $this->location[] = 0;
                $i++;
            }*/
            $this->save();            
        }
    }
    
    private function setAll($arr){
        $this->location = $arr;
    }
    
    function goToL($int, $user){
        if(isset($this->location[$int])){
            $this->location[$int] = 1;
            $this->save();
        }        
        $sql = "UPDATE `".PREFIX_TABLE."users` SET `location` = '".$this->getToString()."' 
                WHERE `kontaktid` = '".$user."'";
        if(!$result = DBConnect::query($sql)){        
            return false;
        }
        return true;
    }
    
    function getToString(){
        return json_encode($this->location);    
    }
    
    function getLocations(){
        
        return @$_SESSION['help']['locations'];
        #$this->location;
    }
    
    function setAllOffString($tarr){
        $this->setAll(json_decode($tarr));
        $this->save();
    }
    
    private function save(){
        $_SESSION['help']['locations'] = $this->location;
    }
}
?>